#include "parsers.h"

#include "items.h"

using namespace fortress;

std::map<int,items*> * parseListen::getItems()
{
	return itemMap;
}

parseListen::parseListen()
{
	itemMap = new std::map<int,items*>;
	i=0;
}

bool parseListen::parserNewStruct(TCODParser *parser,const TCODParserStruct *str,const char *name) 
{
//	printf ("new structure type '%s' with name '%s'\n",str->getName(),name ? name : "NULL");
	temp = new items();
	temp->name = std::string(name);
	return true;
}
bool parseListen::parserFlag(TCODParser *parser,const char *name) 
{
//	printf ("found new flag '%s'\n",name);
	if (!strcmp(name,"walkable"))
		temp->walkable=true;
	else if (!strcmp(name,"canCarry"))
		temp->canCarry=true;
	return true;
}
bool parseListen::parserProperty(TCODParser *parser,const char *name, TCOD_value_type_t type, TCOD_value_t value) 
{
//	printf ("found new property '%s'\n",name);
	if (!strcmp(name,"cost"))
		temp->cost=value.i;
	else if (!strcmp(name,"weight"))
		temp->weight=value.f;
	else if (!strcmp(name,"name"))
		temp->name=std::string(value.s);
	else if (!strcmp(name,"singular"))
		temp->singular=std::string(value.s);
	else if (!strcmp(name,"plural"))
		temp->plural=std::string(value.s);
	else if (!strcmp(name,"baseDamage"))
		temp->baseDamage=value.dice;
	else if (!strcmp(name,"glyph"))
		temp->setGlyph(value.c);
	else if (!strcmp(name,"color"))
		temp->setColor(value.col);
	return true;
}
bool parseListen::parserEndStruct(TCODParser *parser,const TCODParserStruct *str,const char *name) 
{
//	printf ("end of structure type '%s'\n",name);
	itemMap->insert(std::pair<int,items*>(i,temp));
	i++;
	return true;
}
void parseListen::error(const char *msg) 
{
	fprintf(stderr,msg);
	exit(1);
}

